Trò chơi Angry Birds trong UNITY Engine
31.691 lượt xem;
1 using UnityEngine;
2 using System.Collections;
3
4 public class CameraFollow : MonoBehaviour
5 {
6
7 // Use this for initialization
8 void Start()
9 {
10 StartingPosition = transform.position;
11 }
12
13 // Update is called once per frame
14 void Update()
15 {
16 if (IsFollowing)
17 {
18 if (BirdToFollow != null) //bird will be destroyed if it goes out of the scene
19 {
20 var birdPosition = BirdToFollow.transform.position;
21 float x = Mathf.Clamp(birdPosition.x, minCameraX, maxCameraX);
22 //camera follows bird's x position
23 transform.position = new Vector3(x, StartingPosition.y, StartingPosition.z);
24 }
25 else
26 IsFollowing = false;
27 }
28 }
29
30 [HideInInspector]
31 public Vector3 StartingPosition;
32
33
34 private const float minCameraX = 0;
35 private const float maxCameraX = 13;
36 [HideInInspector]
37 public bool IsFollowing;
38 [HideInInspector]
39 public Transform BirdToFollow;
40 }
2 using System.Collections;
3
4 public class CameraFollow : MonoBehaviour
5 {
6
7 // Use this for initialization
8 void Start()
9 {
10 StartingPosition = transform.position;
11 }
12
13 // Update is called once per frame
14 void Update()
15 {
16 if (IsFollowing)
17 {
18 if (BirdToFollow != null) //bird will be destroyed if it goes out of the scene
19 {
20 var birdPosition = BirdToFollow.transform.position;
21 float x = Mathf.Clamp(birdPosition.x, minCameraX, maxCameraX);
22 //camera follows bird's x position
23 transform.position = new Vector3(x, StartingPosition.y, StartingPosition.z);
24 }
25 else
26 IsFollowing = false;
27 }
28 }
29
30 [HideInInspector]
31 public Vector3 StartingPosition;
32
33
34 private const float minCameraX = 0;
35 private const float maxCameraX = 13;
36 [HideInInspector]
37 public bool IsFollowing;
38 [HideInInspector]
39 public Transform BirdToFollow;
40 }